package com.kangkang.leetcode10;

import java.util.Arrays;

public class Test4 {
    public static void main(String[] args) {

        int[] nums = {1,1,1,2,2,3}; // 输入数组
        int[] expectedNums = {1,1,2,2,3}; // 长度正确的期望答案

        int k = Solution4.removeDuplicates(nums); // 调用

        assert k == expectedNums.length;
        for (int i = 0; i < k; i++) {
            assert nums[i] == expectedNums[i];
        }
        System.out.println(Arrays.toString(nums));
    }
}

class Solution4 {
    public static int removeDuplicates(int[] nums) {
        if(nums.length<2){
            return 2;
        }
        int k = 2;
        for (int i = 2; i < nums.length;i++) {
            if (nums[i] != nums[k-2]) {
                nums[k] = nums[i];
                k++;
            }
        }
        return k;
    }


}